//
//  BaseViewController.m
//  BosidengIphone
//
//  Created by  on 11-12-28.
//  Copyright (c) 2011年 __MyCompanyName__. All rights reserved.
//

#import "BaseViewController.h"
#import "AppDelegate.h"

@implementation BaseViewController
@synthesize mainViewController;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        requestQueue = [[NSOperationQueue alloc] init];
        requestQueue.maxConcurrentOperationCount = 1; 
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView
{
}
*/

///*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
    [super viewDidLoad];

}
//*/

- (void)viewDidUnload
{
    [requestQueue cancelAllOperations];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (void)dealloc {
    [mainViewController release];
    [requestQueue release];
    [super dealloc];
}

//设置请求的名称
- (NSDictionary *)setRequestName:(NSString *)name {
    return [NSDictionary dictionaryWithObject:name forKey:@"name"];
}

//返回请求的名称
- (NSString *)getRequestName:(NSDictionary *)userInfo {
    return [userInfo objectForKey:@"name"];
}

//检查是否要删除的本地记录
- (BOOL)isNeedDeleteItem:(NSString *)localId serviceData:(NSArray *)serviceData serviceKey:(NSString *)serviceKey {
    for (NSDictionary *data in serviceData) {
        NSString *serviceId = [data objectForKey:serviceKey];
        if ([localId isEqualToString:serviceId]) {
            return NO;
        }
    }
    return YES;
}

//检查本地文件名和服务器上文件名是否相同
- (BOOL) checkImageUrlIsSame:(NSString *)localUrl serviceUrl:(NSString *)serviceUrl {
    NSString *lcoalName = [localUrl lastPathComponent];
    NSString *serviceName = [serviceUrl lastPathComponent];
    return [lcoalName isEqualToString:serviceName];
}

//根据网络路径取得本地图片缓存路径
- (NSString *)getLocalImagePath:(NSString *)imageUrl {
    NSString *imageName = [imageUrl lastPathComponent];
    NSString *localPath = [AppDelegate getCacheFilePath:imageName];
    return localPath;
}

@end
